package com.zzy.factory.simplefactory.pizzastore.order;

import com.zzy.factory.simplefactory.pizzastore.pizza.CheesePizza;
import com.zzy.factory.simplefactory.pizzastore.pizza.GreekPizza;
import com.zzy.factory.simplefactory.pizzastore.pizza.PepperPizza;
import com.zzy.factory.simplefactory.pizzastore.pizza.Pizza;

/**
 * 简单工厂模式 一个创建对象的类，这个类封装实例化对象的行为
 * 传入一个类型，决定实例化哪一种对象
 * 大量创建某种对象时使用
 */
public class SimplePizzaFactory {
    public Pizza createPizza(String orderType) {
        System.out.println("--------简单工厂模式--------");

        Pizza pizza = null;
        if ("cheese".equals(orderType)) {
            pizza = new CheesePizza();
            pizza.setName("cheese piza");
        } else if ("greek".equals(orderType)) {
            pizza = new GreekPizza();
            pizza.setName("greek piza");
        } else if ("pepper".equals(orderType)) {
            pizza = new PepperPizza();
            pizza.setName("pepper piza");
        }

        return pizza;
    }

    public static Pizza createPizza1(String orderType) {
        System.out.println("--------简单工厂模式2 静态--------");

        Pizza pizza = null;
        if ("cheese".equals(orderType)) {
            pizza = new CheesePizza();
            pizza.setName("cheese piza");
        } else if ("greek".equals(orderType)) {
            pizza = new GreekPizza();
            pizza.setName("greek piza");
        } else if ("pepper".equals(orderType)) {
            pizza = new PepperPizza();
            pizza.setName("pepper piza");
        }

        return pizza;
    }
}
